package xhwl.hmo.mall.views;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;

import xhwl.hmo.mall.R;


public class MyDialog extends Dialog{
	private Context context;
	private WindowManager.LayoutParams layoutParams;
	private DisplayMetrics dm;

	public MyDialog(Activity context, View contentView, int gravity) {
		/* 设计Dialog样式 */
		super(context, R.style.MyDialog);//,
		this.context = context;
		setContentView(contentView);
		// 设置布局显示位置、宽度、透明度、是否浮层
		layoutParams = getWindow().getAttributes();
		layoutParams.gravity = gravity;
		dm = new DisplayMetrics();
		context.getWindowManager().getDefaultDisplay().getMetrics(dm);
		layoutParams.width = dm.widthPixels;
		layoutParams.alpha = 1.0f;
		getWindow().setAttributes(layoutParams);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);//让该window后所有的东西都成暗淡
	}
	public MyDialog(Activity context, View contentView, int gravity, boolean isFullScreen) {
		/* 设计Dialog样式 */
		super(context, R.style.MyDialog);//,
		this.context = context;
		setContentView(contentView);
		// 设置布局显示位置、宽度、透明度、是否浮层
		layoutParams = getWindow().getAttributes();
		layoutParams.gravity = gravity;
		if(isFullScreen){
			dm = new DisplayMetrics();
			context.getWindowManager().getDefaultDisplay().getMetrics(dm);
			layoutParams.width = dm.widthPixels;
		}
		layoutParams.alpha = 1.0f;
		getWindow().setAttributes(layoutParams);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);//让该window后所有的东西都成暗淡
	}
	public MyDialog(int dialog, Activity context, View contentView, int gravity, boolean isFullScreen) {
		/* 设计Dialog样式 */
		super(context,dialog);//,
		this.context = context;
		setContentView(contentView);
		// 设置布局显示位置、宽度、透明度、是否浮层
		layoutParams = getWindow().getAttributes();
		layoutParams.gravity = gravity;
		if(isFullScreen){
			dm = new DisplayMetrics();
			context.getWindowManager().getDefaultDisplay().getMetrics(dm);
			layoutParams.width = dm.widthPixels;
		}
		layoutParams.alpha = 1.0f;
		getWindow().setAttributes(layoutParams);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);//让该window后所有的东西都成暗淡
	}
	public MyDialog(Activity context, View contentView, int gravity, float dimAmount) {
		/* 设计Dialog样式 */
		super(context, R.style.MyDialog);//,
		setContentView(contentView);
		// 设置布局显示位置、宽度、透明度、是否浮层
		layoutParams = getWindow().getAttributes();
		layoutParams.gravity = gravity;
		dm = new DisplayMetrics();
		context.getWindowManager().getDefaultDisplay().getMetrics(dm);
		layoutParams.width = dm.widthPixels;
		layoutParams.alpha = 1.0f;
		layoutParams.dimAmount = dimAmount; // 去背景遮盖
		getWindow().setAttributes(layoutParams);
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);//让该window后所有的东西都成暗淡
	}
	
}
